package com.yc.jpyy.professioncourses.service.imp;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import com.yc.jpyy.base.service.BaseService;
import com.yc.jpyy.professioncourses.dao.ProfessionCoursesDao;
import com.yc.jpyy.professioncourses.service.ProfessionCoursesService;


@Service
public class ProfessionCoursesServiceImpl extends BaseService implements ProfessionCoursesService {
 

@Autowired
private ProfessionCoursesDao professionCoursesDao;

@Override
public Map<String, Object> addProfessionCourses(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int count = professionCoursesDao.addProfessionCourses(paramsMap);
	if(count <= 0){
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "新增失败");
	}else{
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "新增成功");
	}
	return resultMap;
}

@Override
public Map<String, Object> selectProfessionCoursesByPages(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int pagenum = Integer.parseInt(paramsMap.get("pagenum").toString());
	int pagesize = Integer.parseInt(paramsMap.get("pagesize").toString());
	paramsMap.put("pagestart", (pagenum-1) * pagesize);
	List<Map<String,Object>> professionList = professionCoursesDao.selectProfessionCoursesByPages(paramsMap);
	int professionCounts = professionCoursesDao.selectProfessionCoursesCount(paramsMap);
	if(professionList != null && professionList.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData",professionList);
		resultMap.put("TotalCount",professionCounts);
		resultMap.put("TotalPage",professionCounts % pagesize >0 ? professionCounts/pagesize + 1 : professionCounts/pagesize);
		resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "系统无数据");
	}
	return resultMap;
}

@Override
public Map<String, Object> delProfessionCourses(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	paramsMap.put("ids", paramsMap.get("ids").toString().split(","));
	//查询是否有关联子项，否则不能删除
	int counts = professionCoursesDao.selectRelation(paramsMap);
	if(counts > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData", -100);
		resultMap.put("returnMsg", "有相关子项，不能删除");
	}else{	
		int count = professionCoursesDao.delProfessionCourses(paramsMap);
		if(count <= 0){
			resultMap.put("returnCode", 0);
			resultMap.put("returnMsg", "删除失败");
		}else{
			resultMap.put("returnCode", 1);
			resultMap.put("ListData", 1);
			resultMap.put("returnMsg", "删除成功");
		}
	}
	return resultMap;
}

@Override
public Map<String, Object> selectProfessionCourses(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	List<Map<String,Object>>  professionMap = professionCoursesDao.selectProfessionCourses(paramsMap);
	if(professionMap != null && professionMap.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData", professionMap);
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "无数据");
	}
	return resultMap;
}

@Override
public Map<String, Object> updateProfessionCourses(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int i = professionCoursesDao.updateProfessionCourses(paramsMap);
	if(i > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "修改成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "修改失败");
	}
	return resultMap;
}

@Override
public int isOnCoursesNameService(Map<String, Object> paramsMap) throws DataAccessException {
	// TODO Auto-generated method stub
	return professionCoursesDao.isOnCoursesNameDao(paramsMap);
}

}
